﻿<template>
    <div>
        <el-button size="small" @click="search();">刷新</el-button>
        <div class="layout-main">
            <el-table size="small" :data="sysRates" border style="width: 100%" v-loading="loading">
                <el-table-column align="center" prop="countryName" label="国家">
                </el-table-column>
                <el-table-column align="center" prop="country" label="代号">
                    <template slot-scope="scope">
                        <div>{{scope.row.country}}</div>
                        <div>{{scope.row.regionCode}}</div>
                    </template>
                </el-table-column>
                <el-table-column align="center" prop="sellRate" label="汇率">
                    <template slot-scope="scope">
                        <template v-if="scope.row.costEdit">
                            1RMB=
                            <el-input v-model="scope.row.sellRate" size="small" style="width:120px"></el-input>
                            <el-button @click="savePrice(scope.row)" size="small" v-loading="scope.row.costLoading" type="primary">保存</el-button>
                            <el-button @click="scope.row.costLoading=false;scope.row.costEdit=false" size="small">
                                取消
                            </el-button>
                        </template>
                        <template v-else>
                            {{scope.row.sellRate}}
                            <span style="font-size: 16px" @click="editPrice(scope.row)"><i class="el-icon-edit"></i></span>
                        </template>
                    </template>
                </el-table-column>
            </el-table>
        </div>
    </div>
</template>
<script>
export default {
    name: 'SysRate',
    components: {

    },
    data() {
        return {
            loading: false,

            queryParams: {

            },
            others: {

            },
            sysRate: {

            },
            page: {
                total: 0,
                current: 1,
                pageSize: 10
            },
            sysRates: [

            ],
            rules: {}
        };
    },
    mounted: function() {
        this.getList();

    },
    methods: {
        editPrice: function(row) {
            row.costEdit = true;
        },
        savePrice: function(row) {
            var me = this;
            row.costLoading = true;
            me.$http.post("/sysrate/doSave.do", row).then(response => {
                row.costLoading = false;

                if (response.status == 0) {
                    me.successMessage("成功");
                    row.costEdit = false;
                } else {
                    me.errorMessage(response.info);
                    me.getList();
                }
            }, response => {
                row.costLoading = false;
                me.errorMessage("系统异常");
            });
        },
        search: function() {
            this.page.current = 1;
            this.page.total = 0;
            this.getList();
        },
        reset: function() {
            this.queryParams = {};
            this.search();
        },
        changePage(current) {
            this.page.current = current;
            this.getList();
        },
        getList: function() {
            var me = this;
            var params = me.queryParams;
            params.current = me.page.current;
            params.pageSize = me.page.pageSize;
            me.loading = true;
            me.$http.post("/sysrate/getList.do", params).then(response => {
                var body = response;
                if (body.status == 0) {

                    body.obj.forEach((item, ind) => {

                        me.$set(item, "costEdit", false);
                        me.$set(item, "costLoading", false);


                    });
                    me.sysRates = body.obj;

                }
                me.loading = false;
            }, response => {
                me.loading = false;
            });
        }



    }
}
</script>
<style scoped>
</style>